<template>
  <div class="outerBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>基本资料</span>
      </div>
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
<!--        登录用户名-->
        <el-form-item label="用户名" prop="pass" class="typeInput">
          <el-input v-model="ruleForm.userName" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
<!--        用户昵称-->
        <el-form-item label="用户昵称" prop="nickName" class="typeInput">
          <el-input  v-model="ruleForm.nickName"></el-input>
        </el-form-item>
<!--          邮箱-->
        <el-form-item
          class="typeInput"
          prop="email"
          label="邮箱"
        >
          <el-input v-model="ruleForm.email"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">提交</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { changeUserMsg } from '@/api'
export default {
  name: 'user-msg',
  data () {
    return {
      ruleForm: {
        nickName: '',
        userName: '',
        email: '',
        type: true
      },
      rules: {
        nickName: [
          { required: true, message: '请输入用户昵称', trigger: 'blur' },
          { min: 3, max: 6, message: '长度在 3 到 6 个字符', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '请输入邮箱地址', trigger: 'blur' },
          { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
        ]
      }
    }
  },
  mounted () {
    this.ruleForm.userName = this.$store.state.userInfo.username
  },
  methods: {
    async submitForm () {
      const data = {
        id: this.$store.state.userInfo.id,
        username: this.ruleForm.userName,
        email: this.ruleForm.email,
        nickname: this.ruleForm.nickName,
        user_pic: ''
      }
      console.log(data)
      const res = await changeUserMsg(data)
      console.log(res)
    }
  }
}
</script>

<style scoped lang="less">
.outerBox{
  width: 100%;
  height: 500px;
}
.text {
  font-size: 14px;
}
.item {
  margin-bottom: 18px;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}
.box-card {
  width: 98%;
  margin: 20px;
  height: 400px;
}
.typeInput{
  width: 500px;
}
.el-button{
  position: relative;
  top: 10px;
  right: 740px;
}
</style>
